package com.baizhi.controller;

import com.baizhi.service.CmfzUserService;
import com.baizhi.util.GoEasyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: renpu
 * @Date: 2019/2/27 23:18
 * @Description:
 */
@Controller
@RequestMapping("/User")
public class CmfzUserController {
    @Autowired
    private CmfzUserService userService;

    @Autowired
    private GoEasyUtil goEasyUtil;

    @RequestMapping("/showUser")
    @ResponseBody
    public Map showUser(int rows,int page){
        return userService.selectAll(rows,page);
    }

    @RequestMapping("/updateUser")
    public void updateUser(int[] ids){
        userService.update(ids);

    }


    @RequestMapping("/showSexProportion")
    @ResponseBody
    public Map showSexProportion(){

        Map map =new HashMap();
        System.out.println("进入性别展示方法了");
        List<Integer> list=new ArrayList<>();
        int manCount=userService.selectManCount();
        int girlCount=userService.selectGirlCount();
        list.add(manCount);
        list.add(girlCount);
        List<Integer> elist=new ArrayList<>();
        int week1=userService.everyWeekCount(1,15);
        int week2=userService.everyWeekCount(16,30);
        int week3=userService.everyWeekCount(31,45);
        elist.add(week1);
        elist.add(week2);
        elist.add(week3);
        List<Map> flist=userService.selectProvince();
        map.put("list",list);
        map.put("elist",elist);
        map.put("flist",flist);
        goEasyUtil.publish();
        return map;
    }



    @RequestMapping("/everyWeekCount")
    @ResponseBody
    public List<Integer> everyWeekCount(){
        System.out.println("进入统计用户注册量方法");
        List<Integer> list=new ArrayList<>();
        int week1=userService.everyWeekCount(1,15);
        int week2=userService.everyWeekCount(16,30);
        int week3=userService.everyWeekCount(31,45);
        list.add(week1);
        list.add(week2);
        list.add(week3);
        return list;
    }


    @RequestMapping("/selectProvince")
    @ResponseBody
    public List<Map> selectProvince(){
        return userService.selectProvince();
    }
}
